package com.example.leetcode.leetcode.hot100;

import com.example.leetcode.leetcode.tree.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class Solution94 {

    public static List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        midSearch(root, list);
        return list;
    }

    public static void midSearch(TreeNode root, List<Integer> list) {
        if (root == null) return;
        if (root.left != null) {
            midSearch(root.left, list);
        }
        list.add(root.val);
        if (root.right != null) {
            midSearch(root.right, list);
        }
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        TreeNode rl = new TreeNode(2);
        TreeNode rr = new TreeNode(3);
        root.left = rl;
        root.right = rr;
        System.out.println(inorderTraversal(root));
    }
}